import request from '@/utils/request'
enum API {
  ALL_PRO = '/brands/products/selectMine',
  ONE_PAGE_PRO = '/brands/products/selectMinePage',
  ADD_PRO = '/brands/products/add',
  UPDATE_PRO = '/brands/products/update',
  SELECT_NAME = '/brands/products/selectByName',
  DELETE_ONE = '/brands/products/deleteById',
  DELETE_MANY = '/brands/products/deleteBatch',
}
export interface AddParams {
  name: string
  quantity: number
  price: number
  image: string
}
export interface UpdateParams {
  productId: string
  name: string
  quantity: number
  price: number
  image: string
}
export const allProducts = () => request.get(`${API.ALL_PRO}`)
export const pageProducts = (pageNum: number, pageSize: number) =>
  request.get(`${API.ONE_PAGE_PRO}?pageNum=${pageNum}&pageSize=${pageSize}`)

export const selectByName = (name: string) => request.get(`${API.SELECT_NAME}/${name}`)
export const addProduct = (params: AddParams) => request.post(`${API.ADD_PRO}`, params)
export const updateProduct = (params: UpdateParams) => request.put(`${API.UPDATE_PRO}`, params)
export const deleteOne = (productId: string) => request.put(`${API.DELETE_ONE}/${productId}`)
export const deleteMany = (params: string[]) =>
  request.delete(`${API.DELETE_MANY}`, {
    data: params,
  })
export const uploadPic = (file: object) => request.post(`/files/upload?file=${file}`)
